package com.ifreeee.practice.pc.map;

import java.util.Map;

public class MapUtils {


    public static void printMap(Map map) {
        System.out.println(printMap("", map));
    }

    /**
     * 按行打印 map
     *
     * @param map
     * @return
     */
    public static StringBuilder printMap(String pre, Map map) {
        StringBuilder sb = new StringBuilder();
        if (org.apache.commons.collections4.MapUtils.isEmpty(map)) {
            return sb;
        }
        map.forEach((k, v) -> {
            sb.append(pre);
            if (v instanceof Map) {
                sb.append(k);
                sb.append(": ");
                sb.append("\n");
                sb.append(printMap(pre + "    ", (Map) v));
            } else {
                sb.append(k);
                sb.append("    <====>    ");
                sb.append(v);
            }
            sb.append("\n");
        });
        return sb;
    }

}
